< previous page page_407 next page >

Page 407
by Visual Basic. By using a different name for the declaration, it becomes possible to use OpenSCManager as the name of a public method for the class itself. This does mean that you have to be careful when writing the class to distinguish between the two names. But clients using the class will be able to use the more familiar namethey won't have access to the name used in the API declaration.
The CloseServiceHandle function is trivial by comparison. It takes an SC_HANDLE parameter, which is simply a 32-bit Long passed ByVal as follows:
Public Declare Function CloseServiceHandle Lib "advapi32" (ByVal _
schandle As Long) As Long
The EnumServicesStatus function is a bit trickier. The first thing to notice is that you must distinguish between the parameters that are specified as DWORD parameters and those specified as LPDWORD. The DWORD parameters are long values and are thus defined as Long parameters that are passed ByVal. The LPDWORD parameters are pointers to DWORD (long) values and are thus defined as Long parameters that are passed ByRef. The lpServices parameter is defined for now as a Long passed ByVal. Why? Because we'll be calculating the pointer in code and passing that pointer value to the function:
BOOL EnumServicesStatus(
    SC_HANDLE hSCManager, // handle to service control manager database
    DWORD dwServiceType,  // type of services to enumerate
    DWORD dwServiceState, // state of services to enumerate
    LPENUM_SERVICE_STATUS lpServices,      // pointer to service status buffer
    DWORD cbBufSize,      // size of service status buffer
    LPDWORD pcbBytesNeeded,       // pointer to variable for bytes needed
    LPDWORD lpServicesReturned,   // pointer to variable for number returned
    LPDWORD lpResumeHandle        // pointer to variable for next entry
   );
The resulting declaration is as follows:
Public Declare Function intEnumServicesStatus Lib "advapi32" _
Alias "EnumServicesStatusA" _
    (ByVal hSCManager As Long, _
    ByVal dwServiceType As Long, _
    ByVal dwServiceState As Long, _
    ByVal lpServices As Long, _
    ByVal cbBufSize As Long, _
    pcbBytesNeeded As Long, _
    lpServicesReturned As Long, _
    lpResumeHandle As Long) As Long

 
< previous page page_407 next page >